package student;

import java.util.Scanner;

public class Caozuo {
    int count=0;
    Student[] students=new Student[50];
public  void start(){
    System.out.println("====欢迎登录学生管理系统====");
    System.out.println("请选择您的操作");
    System.out.println("1.添加学生");
    System.out.println("2.修改学生");
    System.out.println("3.删除学生");
    System.out.println("4.查看学生");
    System.out.println("5.退出");
    Scanner scanner=new Scanner(System.in);



    while (true){
        int num=scanner.nextInt();
        switch (num){
            case 1:
                addName();
               break;
            case 2:
                updatetName();
                break;
            case 3:
                chakan();
break;
            case 4:
                shanchu();
                break;
            case 5:
                logout();
                break;
        }
    }

  }
    private void addName(){

        System.out.println("添加学生");
        Scanner scanner1=new Scanner(System.in);
        System.out.println("请输入学号");
        int sid= scanner1.nextInt();
        System.out.println("请输入姓名");
        String sname= scanner1.next();
        System.out.println("请输入年龄");
        int sage= scanner1.nextInt();
        System.out.println("请输入学号");
        int smax = scanner1.nextInt();
        Student student=new Student(sid,sname,sage,smax);
        System.out.println(student);

students[count]=student;
count++;
        System.out.println("添加成功");
    }
    private   void updatetName(){
        System.out.println("修改");
        Scanner scanner1=new Scanner(System.in);
        System.out.println("请输入你要修改的学号");
        int sid= scanner1.nextInt();
        System.out.println("请输入姓名");
        String sname= scanner1.next();
        System.out.println("请输入年龄");
        int sage= scanner1.nextInt();
        System.out.println("请输入学号");
        int smax = scanner1.nextInt();
        for (int i=0;i<count;i++){
            if(sid==students[i].getSid()){
                students[i].setSname(sname);
                students[i].setSage(sage);
                students[i].setSmax(smax);
            }
        }




    }
    private void chakan(){
        System.out.println("查看");
        System.out.println(students.length);
for (int i=0;i<count;i++){

    System.out.println("学生"+students[i].getSid()+students[i].getSname()+students[i].getSage()+students[i].getSmax());
}
    }
    private void shanchu(){
    Scanner scanner=new Scanner(System.in);
        System.out.println("请输入你要修改的学号");
        int sid=scanner.nextInt();
        Student[] newstudent=new Student[10];
        for (int i=0;i<count;i++){
            if(sid!=students[i].getSid()){
                newstudent[i]=students[i];
            }
        }
        students=newstudent;
        count--;
        System.out.println("删除成功");
    }
    private void  logout(){
        System.out.println("退出成功");
        return;
    }
}
